/*****************************************************************************\
*																			  *
* Replication do-file for Renanah Joyce, Theodore McLauchlin and Lee Seymour, *
* "'Train the World': Examining the Logics of US Foreign Military Training",  *
* International Studies Quarterly                                             *
* Analyses conducted using Stata 13											  *
*																			  *
\*****************************************************************************/

log using traintheworld, replace
set more off

//Packages required: coefplot and outreg2
ssc install coefplot, replace
ssc install outreg2, replace 

use traintheworld.dta, clear

//sets time-series structure and graph appearance
xtset ccode year
set scheme s2simple


//text claims (Data and Methods section) regarding threat distance and training for states for which, from 2001 onward, the Departments of State and Defense do not need to report training expenditures (NATO, Australia, New Zealand, Japan)
ttest minthreatdist if ccode!=2 & year > 1998 & regforce==1, by(NATOAndOthers)
ttest log_trainees if ccode!=2 & year > 1998 & year < 2001 & regforce==1, by(NATOAndOthers)
ttest log_trainexp if ccode!=2 & year > 1998 & year < 2001 & regforce==1, by(NATOAndOthers)

//text claims (Data and Methods section) regarding traning in states about to join NATO during the period the paper covers (1999-2018)
ttest log_trainees if NATOAndOthers==0 & year > 1998 & regforce==1, by(about_to_join_NATO)
ttest log_trainexp if NATOAndOthers==0 & year > 1998 & regforce==1, by(about_to_join_NATO)

//TABLE 1: Threats and US training (country-years)
tab threat traineesbin if NATOAndOthers==0 & year >=1999 & regforce==1, row

//FIGURE 1: Percentage of non-threat states trained by US, with lowess smooth
preserve
keep if NATOAndOthers==0
keep if threat==0
keep if regforce==1
collapse (sum) traineesbin dummy, by(year)
gen traineespct = traineesbin/dummy*100
keep if year >=1999
twoway (scatter traineespct year) (lowess traineespct year), legend(off) ytitle("Percentage of countries trained")
restore
graph export figure1.tif, width(1200) replace


//TABLE 2 -- MAIN RESULTS TABLE
//external threats
xtreg log_trainees coup_suc_lag1 log_trainees_lag1 threat_lag1 c.mingtidist_lag1##c.ideal_point_lag1 if NATOAndOthers==0 & year>=1999 & iraqaf==0 & regforce==1, re vce(robust)
outreg2 using table2.xls, replace title(Cross-section time-series results, with country random effects) ctitle(Trainees) label
xtreg log_trainexp coup_suc_lag1 log_trainexp_lag1 threat_lag1 c.mingtidist_lag1##c.ideal_point_lag1 if NATOAndOthers==0 & year>=1999 & iraqaf==0 & regforce==1, re vce(robust)
outreg2 using table2.xls, append ctitle(Expenditures) label
//internal threats
xtreg log_trainees coup_suc_lag1 log_trainees_lag1 imf_tax_lag1 rebels_combined_lag1##c.ideal_point_lag1  if NATOAndOthers==0 & year>=1999 & iraqaf==0 & regforce==1, re vce(robust)
outreg2 using table2.xls, append ctitle(Trainees) label
xtreg log_trainexp coup_suc_lag1 log_trainexp_lag1 imf_tax_lag1  rebels_combined_lag1##c.ideal_point_lag1  if NATOAndOthers==0 & year>=1999 & iraqaf==0 & regforce==1, re vce(robust)
outreg2 using table2.xls, append ctitle(Expenditures) label
xtreg log_trainees coup_suc_lag1 log_trainees_lag1 imf_tax_lag1 islamist_combined_lag1##c.ideal_point_lag1 if NATOAndOthers==0 & year>=1999 & iraqaf==0 & regforce==1, re vce(robust)
outreg2 using table2.xls, append ctitle(Trainees) label
xtreg log_trainexp coup_suc_lag1 log_trainexp_lag1 imf_tax_lag1  islamist_combined_lag1##c.ideal_point_lag1  if NATOAndOthers==0 & year>=1999 & iraqaf==0 & regforce==1, re vce(robust)
outreg2 using table2.xls, append ctitle(Expenditures) label
//norm transmission
xtreg log_trainees coup_suc_lag1 log_trainees_lag1  demtrans_last5_ert v2x_regime_lag1 if NATOAndOthers==0 & year>=1999 & iraqaf==0 & regforce==1, re vce(robust)
outreg2 using table2.xls, append ctitle(Trainees) label
xtreg log_trainexp coup_suc_lag1 log_trainexp_lag1 demtrans_last5_ert v2x_regime_lag1  if NATOAndOthers==0 & year>=1999 & iraqaf==0 & regforce==1, re vce(robust)
outreg2 using table2.xls, append ctitle(Expenditures) label
//full model
xtreg log_trainees coup_suc_lag1 log_trainees_lag1  threat_lag1 c.mingtidist_lag1##c.ideal_point_lag1 imf_tax_lag1  rebels_combined_lag1##c.ideal_point_lag1 demtrans_last5_ert v2x_regime_lag1 log_wb_pop_lag1 if NATOAndOthers==0 & year>=1999 & iraqaf==0 & regforce==1, re vce(robust)
gen mainsample = e(sample)
label var mainsample "Is in main sample, Model 9, Table 2"
estimates store mod9
outreg2 using table2.xls, append ctitle(Trainees) label
xtreg log_trainexp coup_suc_lag1 log_trainexp_lag1 threat_lag1 c.mingtidist_lag1##c.ideal_point_lag1 imf_tax_lag1  rebels_combined_lag1##c.ideal_point_lag1 demtrans_last5_ert v2x_regime_lag1 log_wb_pop_lag1  if NATOAndOthers==0 & year>=1999 & iraqaf==0 & regforce==1, re vce(robust)
estimates store mod10
outreg2 using table2.xls, append ctitle(Expenditures) label


//text claim (Results section, after Table 2) about correlation between democracy and ideal point
corr v2x_regime_lag1 threat_lag1 mingtidist_lag1 ideal_point_lag1 imf_tax_lag1 rebels_combined_lag1 log_wb_pop_lag1


//FIGURE 2. How the interaction of diplomatic alignment and threats relates to training
centile mingtidist_lag1, centile(5 10 50 90 95)
centile ideal_point_lag1, centile(5 10 50 90 95)
//FIGURE 2a. Interacting diplomatic alignment and external threat environment
estimates restore mod9
margins, at(mingtidist_lag1 = (0.5 0.75 1 1.25 1.5 1.75 2 2.25 2.5 2.75 3) ideal_point_lag1 = -1) post
estimates store align_n1
estimates restore mod9
margins, at(mingtidist_lag1 = (0.5 0.75 1 1.25 1.5 1.75 2 2.25 2.5 2.75 3) ideal_point_lag1 = 0) post
estimates store align_0
estimates restore mod9
margins, at(mingtidist_lag1 = (0.5 0.75 1 1.25 1.5 1.75 2 2.25 2.5 2.75 3) ideal_point_lag1 = 1) post
estimates store align_1
coefplot align_n1 align_1, at ytitle(Predicted log trainees) xtitle (US-centric threat environment) recast(line) lwidth(*2) ciopts(recast(rarea)) ///
 legend(c(3) r(1) label(2 "-1") label(4 "+1")  title("Ideal point from UNGA voting"))
graph export figure2a.tif, width(1200) replace
//FIGURE 2b. Interacting diplomatic alignment and civil conflicts
estimates restore mod9
margins, at(rebels_combined_lag1 = (0 1) ideal_point_lag = -1)
matrix AN1 = r(table)
matrix reb_results = AN1[1, 1..2]
matrix reb_results = reb_results \ AN1["ll", 1..2]
matrix reb_results = reb_results \ AN1["ul", 1..2]
matrix reb_results = reb_results \ (-1,-1\0,1)
estimates restore mod9
margins, at(rebels_combined_lag1 = (0 1) ideal_point_lag = 0)
matrix A0 = r(table)
matrix reb_results_0 = A0["b", 1..2]
matrix reb_results_0 = reb_results_0 \ A0["ll".."ul", 1..2]
matrix reb_results_0 = reb_results_0 \ (0,0\0,1)
estimates restore mod9
margins, at(rebels_combined_lag1 = (0 1) ideal_point_lag = 1) 
matrix A1 = r(table)
matrix reb_results_1 = A1["b", 1..2]
matrix reb_results_1 = reb_results_1 \ A1["ll".."ul", 1..2]
matrix reb_results_1 = reb_results_1 \ (1,1\0,1)
matrix reb_results = reb_results, reb_results_0, reb_results_1
matrix list reb_results
matrix rownames reb_results = b ll ul idealpt rebel
matrix reb_results = reb_results'
preserve
clear
svmat reb_results, names(col)
replace rebel = rebel - 0.01 in 1/2
replace rebel = rebel + 0.01 in 5/6
twoway (scatter b rebel if idealpt==-1, mcol(navy)) (rspike ll ul rebel if idealpt==-1, lcol(navy)) ///
 (scatter b rebel if idealpt==1, mcol(maroon)) (rspike ll ul rebel if idealpt==1, lcol(maroon)) ///
 , ytitle(Predicted log trainees) xtitle(" ") xlab(0 "No rebellion" 1 "Rebellion") ///
 xscale(range(-0.25 1.25)) ///
 legend(order(2 4 6) r(1) label(2 "-1") label(4 "+1") title("Ideal point from UNGA voting"))
graph export figure2b.tif, width(1200) replace
restore

//Text claim (results section, around  Figure 2): substantive relationships are substantially the same for expenditures
estimates restore mod10
margins, at(mingtidist_lag1 = (0.5 0.75 1 1.25 1.5 1.75 2 2.25 2.5 2.75 3) ideal_point_lag1 = -1) post
estimates store align_n1
estimates restore mod10
margins, at(mingtidist_lag1 = (0.5 0.75 1 1.25 1.5 1.75 2 2.25 2.5 2.75 3) ideal_point_lag1 = 0) post
estimates store align_0
estimates restore mod10
margins, at(mingtidist_lag1 = (0.5 0.75 1 1.25 1.5 1.75 2 2.25 2.5 2.75 3) ideal_point_lag1 = 1) post
estimates store align_1
coefplot align_n1 align_1, at ytitle(Predicted log training expenditures) xtitle (US-centric threat environment) recast(line) lwidth(*2) ciopts(recast(rarea)) ///
 legend(c(3) r(1) label(2 "-1") label(4 "+1")  title("Ideal point from UNGA voting"))

estimates restore mod10
margins, at(rebels_combined_lag1 = (0 1) ideal_point_lag = -1)
matrix AN1 = r(table)
matrix reb_results = AN1[1, 1..2]
matrix reb_results = reb_results \ AN1["ll", 1..2]
matrix reb_results = reb_results \ AN1["ul", 1..2]
matrix reb_results = reb_results \ (-1,-1\0,1)
estimates restore mod10
margins, at(rebels_combined_lag1 = (0 1) ideal_point_lag = 0)
matrix A0 = r(table)
matrix reb_results_0 = A0["b", 1..2]
matrix reb_results_0 = reb_results_0 \ A0["ll".."ul", 1..2]
matrix reb_results_0 = reb_results_0 \ (0,0\0,1)
estimates restore mod10
margins, at(rebels_combined_lag1 = (0 1) ideal_point_lag = 1) 
matrix A1 = r(table)
matrix reb_results_1 = A1["b", 1..2]
matrix reb_results_1 = reb_results_1 \ A1["ll".."ul", 1..2]
matrix reb_results_1 = reb_results_1 \ (1,1\0,1)
matrix reb_results = reb_results, reb_results_0, reb_results_1
matrix list reb_results
matrix rownames reb_results = b ll ul idealpt rebel
matrix reb_results = reb_results'
preserve
clear
svmat reb_results, names(col)
replace rebel = rebel - 0.01 in 1/2
replace rebel = rebel + 0.01 in 5/6
twoway (scatter b rebel if idealpt==-1, mcol(navy)) (rspike ll ul rebel if idealpt==-1, lcol(navy)) ///
 (scatter b rebel if idealpt==1, mcol(maroon)) (rspike ll ul rebel if idealpt==1, lcol(maroon)) ///
 , ytitle(Predicted log training expenditures) xtitle(" ") xlab(0 "No rebellion" 1 "Rebellion") ///
 xscale(range(-0.25 1.25)) ///
 legend(order(2 4 6) r(1) label(2 "-1") label(4 "+1") title("Ideal point from UNGA voting"))
restore


//text estimates (results section, after Figure 2) of substantive relationships between threat and training
estimates restore mod9
margins, at(mingtidist_lag1 = (0.5 3) ideal_point_lag1 = 1)
matrix m1 = r(b)				
scalar expm11 = exp(m1[1,1])			//this converts the first estimated margin to unlogged trainees
scalar list expm11
scalar expm12 = exp(m1[1,2])			//this converts the second estimated margin to unlogged trainees
scalar list expm12

estimates restore mod10
margins, at(mingtidist_lag1 = (0.5 3) ideal_point_lag1 = 1)
matrix m2 = r(b)				
scalar expm21 = exp(m2[1,1])			//this converts the first estimated margin to unlogged dollars
scalar list expm21
scalar expm22 = exp(m2[1,2])			//this converts the second estimated margin to unlogged dollars
scalar list expm22

estimates restore mod9
margins, at(rebels_combined_lag1 = (0 1) ideal_point_lag1 = 1)
matrix m3 = r(b)				
scalar expm31 = exp(m3[1,1])			//this converts the first estimated margin to unlogged trainees
scalar list expm31
scalar expm32 = exp(m3[1,2])			//this converts the second estimated margin to unlogged trainees
scalar list expm32

estimates restore mod10
margins, at(rebels_combined_lag1 = (0 1) ideal_point_lag1 = 1)
matrix m4 = r(b)				
scalar expm41 = exp(m4[1,1])			//this converts the first estimated margin to unlogged dollars
scalar list expm41
scalar expm42 = exp(m4[1,2])			//this converts the second estimated margin to unlogged dollars
scalar list expm42



//APPENDIX

//appendix table 1 -- descriptives
su log_trainees log_trainexp coup_suc_lag1 threat_lag1 mingtidist_lag1 ideal_point_lag1 imf_tax_lag1 rebels_combined_lag1 islamist_combined_lag1 demtrans_last5_ert v2x_regime_lag1 log_wb_pop_lag1 if mainsample==1

//appendix figure 1 -- histograms of training
hist log_trainees if mainsample==1, xtitle("Log trainees")
graph export figureA1a.tif, width(1200) replace
hist log_trainexp if mainsample==1, xtitle("Log training expenditures")
graph export figureA1b.tif, width(1200) replace

//appendix table 2 -- democracy-training relationship weakens when ideal point is introduced
xtreg log_trainees coup_suc_lag1 log_trainees_lag1  demtrans_last5_ert v2x_regime_lag1 if NATOAndOthers==0 & year>=1999 & iraqaf==0 & regforce==1, re vce(robust)
outreg2 using tableA2.xls, replace title(Cross-section time-series results, clarifying the relationship between democracy and training) ctitle(Trainees) label
xtreg log_trainexp coup_suc_lag1 log_trainexp_lag1 demtrans_last5_ert v2x_regime_lag1  if NATOAndOthers==0 & year>=1999 & iraqaf==0 & regforce==1, re vce(robust)
outreg2 using tableA2.xls, append ctitle(Expenditures) label
xtreg log_trainees coup_suc_lag1 log_trainees_lag1   ideal_point_lag1 demtrans_last5_ert v2x_regime_lag1 if NATOAndOthers==0 & year>=1999 & iraqaf==0 & regforce==1, re vce(robust)
outreg2 using tableA2.xls, append ctitle(Trainees) label
xtreg log_trainexp coup_suc_lag1 log_trainexp_lag1   ideal_point_lag1 demtrans_last5_ert v2x_regime_lag1 if NATOAndOthers==0 & year>=1999 & iraqaf==0 & regforce==1, re vce(robust)
outreg2 using tableA2.xls, append ctitle(Expenditures) label


//appendix table 3 -- including Iraq and Afghanistan
//external threats
xtreg log_trainees coup_suc_lag1 log_trainees_lag1 iraq afgh threat_lag1 c.mingtidist_lag1##c.ideal_point_lag1 if NATOAndOthers==0 & year>=1999 & regforce==1, re vce(robust)
outreg2 using tableA3.xls, replace title(Cross-section time-series results, including Iraq and Afghanistan) ctitle(Trainees) label
xtreg log_trainexp coup_suc_lag1 log_trainexp_lag1 iraq afgh threat_lag1 c.mingtidist_lag1##c.ideal_point_lag1 if NATOAndOthers==0 & year>=1999 & regforce==1, re vce(robust)
outreg2 using tableA3.xls, append ctitle(Expenditures) label
//internal threats
xtreg log_trainees coup_suc_lag1 log_trainees_lag1 iraq afgh imf_tax_lag1 rebels_combined_lag1##c.ideal_point_lag1  if NATOAndOthers==0 & year>=1999  & regforce==1, re vce(robust)
outreg2 using tableA3.xls, append ctitle(Trainees) label
xtreg log_trainexp coup_suc_lag1 log_trainexp_lag1 iraq afgh imf_tax_lag1  rebels_combined_lag1##c.ideal_point_lag1  if NATOAndOthers==0 & year>=1999 & regforce==1, re vce(robust)
outreg2 using tableA3.xls, append ctitle(Expenditures) label
xtreg log_trainees coup_suc_lag1 log_trainees_lag1 iraq afgh imf_tax_lag1 islamist_combined_lag1##c.ideal_point_lag1 if NATOAndOthers==0 & year>=1999 & regforce==1, re vce(robust)
outreg2 using tableA3.xls, append ctitle(Trainees) label
xtreg log_trainexp coup_suc_lag1 log_trainexp_lag1 iraq afgh imf_tax_lag1  islamist_combined_lag1##c.ideal_point_lag1  if NATOAndOthers==0 & year>=1999  & regforce==1, re vce(robust)
outreg2 using tableA3.xls, append ctitle(Expenditures) label
//norm transmission
xtreg log_trainees coup_suc_lag1 log_trainees_lag1 iraq afgh demtrans_last5_ert v2x_regime_lag1 if NATOAndOthers==0 & year>=1999  & regforce==1, re vce(robust)
outreg2 using tableA3.xls, append ctitle(Trainees) label
xtreg log_trainexp coup_suc_lag1 log_trainexp_lag1 iraq afgh demtrans_last5_ert v2x_regime_lag1  if NATOAndOthers==0 & year>=1999 & regforce==1, re vce(robust)
outreg2 using tableA3.xls, append ctitle(Expenditures) label
//full model
xtreg log_trainees coup_suc_lag1 log_trainees_lag1 iraq afgh threat_lag1 c.mingtidist_lag1##c.ideal_point_lag1 imf_tax_lag1  rebels_combined_lag1##c.ideal_point_lag1 demtrans_last5_ert v2x_regime_lag1 log_wb_pop_lag1 if NATOAndOthers==0 & year>=1999  & regforce==1, re vce(robust)
outreg2 using tableA3.xls, append ctitle(Trainees) label
xtreg log_trainexp coup_suc_lag1 log_trainexp_lag1 iraq afgh threat_lag1 c.mingtidist_lag1##c.ideal_point_lag1 imf_tax_lag1  rebels_combined_lag1##c.ideal_point_lag1 demtrans_last5_ert v2x_regime_lag1 log_wb_pop_lag1  if NATOAndOthers==0 & year>=1999  & regforce==1, re vce(robust)
outreg2 using tableA3.xls, append ctitle(Expenditures) label


//appendix table 4 -- with country fixed effects
//external threats
xtreg log_trainees coup_suc_lag1 log_trainees_lag1 threat_lag1 c.mingtidist_lag1##c.ideal_point_lag1 if NATOAndOthers==0 & year>=1999 & iraqaf==0 & regforce==1, fe vce(robust)
outreg2 using tableA4.xls, replace title(Cross-section time-series results, with country fixed effects) ctitle(Trainees) label
xtreg log_trainexp coup_suc_lag1 log_trainexp_lag1 threat_lag1 c.mingtidist_lag1##c.ideal_point_lag1 if NATOAndOthers==0 & year>=1999 & iraqaf==0 & regforce==1, fe vce(robust)
outreg2 using tableA4.xls, append ctitle(Expenditures) label
//internal threats
xtreg log_trainees coup_suc_lag1 log_trainees_lag1 imf_tax_lag1 rebels_combined_lag1##c.ideal_point_lag1  if NATOAndOthers==0 & year>=1999 & iraqaf==0 & regforce==1, fe vce(robust)
outreg2 using tableA4.xls, append ctitle(Trainees) label
xtreg log_trainexp coup_suc_lag1 log_trainexp_lag1 imf_tax_lag1  rebels_combined_lag1##c.ideal_point_lag1  if NATOAndOthers==0 & year>=1999 & iraqaf==0 & regforce==1, fe vce(robust)
outreg2 using tableA4.xls, append ctitle(Expenditures) label
xtreg log_trainees coup_suc_lag1 log_trainees_lag1 imf_tax_lag1 islamist_combined_lag1##c.ideal_point_lag1 if NATOAndOthers==0 & year>=1999 & iraqaf==0 & regforce==1, fe vce(robust)
outreg2 using tableA4.xls, append ctitle(Trainees) label
xtreg log_trainexp coup_suc_lag1 log_trainexp_lag1 imf_tax_lag1  islamist_combined_lag1##c.ideal_point_lag1  if NATOAndOthers==0 & year>=1999 & iraqaf==0 & regforce==1, fe vce(robust)
outreg2 using tableA4.xls, append ctitle(Expenditures) label
//norm transmission
xtreg log_trainees coup_suc_lag1 log_trainees_lag1  v2x_regime_lag1 if NATOAndOthers==0 & year>=1999 & iraqaf==0 & regforce==1, fe vce(robust)
outreg2 using tableA4.xls, append ctitle(Trainees) label
xtreg log_trainexp coup_suc_lag1 log_trainexp_lag1 v2x_regime_lag1  if NATOAndOthers==0 & year>=1999 & iraqaf==0 & regforce==1, fe vce(robust)
outreg2 using tableA4.xls, append ctitle(Expenditures) label
//full model
xtreg log_trainees coup_suc_lag1 log_trainees_lag1  threat_lag1 c.mingtidist_lag1##c.ideal_point_lag1 imf_tax_lag1  rebels_combined_lag1##c.ideal_point_lag1 v2x_regime_lag1 if NATOAndOthers==0 & year>=1999 & iraqaf==0 & regforce==1, fe vce(robust)
estimates store mod9fe
outreg2 using tableA4.xls, append ctitle(Trainees) label
xtreg log_trainexp coup_suc_lag1 log_trainexp_lag1 threat_lag1 c.mingtidist_lag1##c.ideal_point_lag1 imf_tax_lag1  rebels_combined_lag1##c.ideal_point_lag1 v2x_regime_lag1 if NATOAndOthers==0 & year>=1999 & iraqaf==0 & regforce==1, fe vce(robust)
outreg2 using tableA4.xls, append ctitle(Expenditures) label

// appendix figure 2
estimates restore mod9fe
margins, at(mingtidist_lag1 = (0.5 0.75 1 1.25 1.5 1.75 2 2.25 2.5 2.75 3) ideal_point_lag1 = -1) post
estimates store align_n1
estimates restore mod9fe
margins, at(mingtidist_lag1 = (0.5 0.75 1 1.25 1.5 1.75 2 2.25 2.5 2.75 3) ideal_point_lag1 = 0) post
estimates store align_0
estimates restore mod9fe
margins, at(mingtidist_lag1 = (0.5 0.75 1 1.25 1.5 1.75 2 2.25 2.5 2.75 3) ideal_point_lag1 = 1) post
estimates store align_1
coefplot align_n1 align_1, at ytitle(Predicted log trainees) xtitle (US-centric threat environment) recast(line) lwidth(*2) ciopts(recast(rarea)) ///
	legend(c(3) r(1) label(2 "-1") label(4 "+1")  title("Ideal point from UNGA voting"))


//appendix table 5 -- alternative measures

//state strength -- military personnel per capita (World Bank)
xtreg log_trainees coup_suc_lag1 log_trainees_lag1 milpc_lag1 rebels_combined_lag1##c.ideal_point_lag1  if NATOAndOthers==0 & year>=1999 & iraqaf==0 & regforce==1, re vce(robust)
outreg2 using tableA5.xls, replace title(Cross-sectional time-series estimates, alternate measures) ctitle(Trainees) label
xtreg log_trainexp coup_suc_lag1 log_trainexp_lag1 milpc_lag1  rebels_combined_lag1##c.ideal_point_lag1  if NATOAndOthers==0 & year>=1999 & iraqaf==0 & regforce==1, re vce(robust)
outreg2 using tableA5.xls, append ctitle(Expenditures) label
//democracy (boix et al)
xtreg log_trainees coup_suc_lag1 log_trainees_lag1  demtrans_last5 democracy_lag1 if NATOAndOthers==0 & year>=1999 & iraqaf==0 & regforce==1, re vce(robust)
outreg2 using tableA5.xls, append ctitle(Trainees) label
xtreg log_trainexp coup_suc_lag1 log_trainexp_lag1 demtrans_last5 democracy_lag1  if NATOAndOthers==0 & year>=1999 & iraqaf==0 & regforce==1, re vce(robust)
outreg2 using tableA5.xls, append ctitle(Expenditures) label
//full model
xtreg log_trainees coup_suc_lag1 log_trainees_lag1  threat_lag1 c.mingtidist_lag1##c.ideal_point_lag1 milpc_lag1  rebels_combined_lag1##c.ideal_point_lag1 demtrans_last5 democracy_lag1 log_wb_pop_lag1 if NATOAndOthers==0 & year>=1999 & iraqaf==0 & regforce==1, re vce(robust)
outreg2 using tableA5.xls, append ctitle(Trainees) label
xtreg log_trainexp coup_suc_lag1 log_trainexp_lag1 threat_lag1 c.mingtidist_lag1##c.ideal_point_lag1 milpc_lag1  rebels_combined_lag1##c.ideal_point_lag1 demtrans_last5 democracy_lag1 log_wb_pop_lag1  if NATOAndOthers==0 & year>=1999 & iraqaf==0 & regforce==1, re vce(robust)
outreg2 using tableA5.xls, append ctitle(Expenditures) label

//appendix table 6 - included and excluded country years
preserve
keep if year >=1999 // first year of training data; there are prior years due to lagged independent variables
drop if year >=2008 & ccode == 347 // Kosovo, independent in 2008
drop if year >=2011 & ccode == 626 // South Sudan, independent in 2011
sort country year
keep country ccode year mainsample log_trainees coup_suc_lag1 log_trainees_lag1  threat_lag1 mingtidist_lag1 ideal_point_lag1 imf_tax_lag1  rebels_combined_lag1 demtrans_last5_ert v2x_regime_lag1 log_wb_pop_lag1 NATOAndOthers iraqaf regforce
export excel using "sample data.xlsx", firstrow(varlabels)
restore

log close
